package com.guigu.leizihao.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.common.mapper.SCellMapper;
import com.guigu.common.pojo.SCell;
import com.guigu.common.util.GetUUidUtil;
import com.guigu.leizihao.service.ScellService;
import com.guigu.common.vo.SearchVo;
import com.guigu.leizihao.vo.ScellCountVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class ScellServiceImpl implements ScellService {

    @Resource
    private GetUUidUtil getUUidUtil;

    @Resource
        private  SCellMapper sCellMapper;

    @Override
    public SearchVo queryDfile(SearchVo s) {
        PageHelper.startPage(s.getPageNumber(),s.getPageSize());
        PageInfo p=new PageInfo(this.sCellMapper.queryDfile(s));
        s.setRows(p.getList());
        s.setTotal(p.getTotal());
        return s;
    }

    @Override
    public int addScellService(SCell sCell) {
        String s = this.getUUidUtil.returnId("400");
        System.out.println(s);
        sCell.setStoreId(s);
        int i = this.sCellMapper.insertSelective(sCell);
        int i1 = this.sCellMapper.updateDfileDESIGN_CELL_TAG(sCell.getProductId());
        if(i>0 && i1>0){

            return 1;
        }

        return 0;
    }

    @Override
    public SearchVo queryScellCheck(SearchVo searchVo) {

        PageHelper.startPage(searchVo.getPageNumber(),searchVo.getPageSize());

        PageInfo p=new PageInfo(this.sCellMapper.queryScellCheck(searchVo));
        searchVo.setTotal(p.getTotal());
        searchVo.setRows(p.getList());
        return searchVo;
    }

    @Override
    public int review(String storeId,String checker) {
        SCell s=new SCell();
        s.setChecker(checker);
        s.setStoreId(storeId);
        return this.sCellMapper.review(s);
    }

    @Override
    public SearchVo queryScellAll(SearchVo searchVo) {
        PageHelper.startPage(searchVo.getPageNumber(),searchVo.getPageSize());
        PageInfo p=new PageInfo( this.sCellMapper.queryScellAll(searchVo));
        searchVo.setRows(p.getList());
        searchVo.setTotal(p.getTotal());
        return searchVo;
    }

    @Override
    public SearchVo queryScellChenge(SearchVo searchVo) {
        PageHelper.startPage(searchVo.getPageNumber(),searchVo.getPageSize());
        PageInfo p=new PageInfo(this.sCellMapper.queryScellChenge(searchVo));
        searchVo.setTotal(p.getTotal());
        searchVo.setRows(p.getList());
        return searchVo;
    }

    @Override
    public int ScellChange(SCell sCell) {
        return this.sCellMapper.updateByPrimaryKeySelective(sCell);
    }

    @Override
    public ScellCountVo queryCount() {
        return this.sCellMapper.queryCellCount();
    }

    @Override
    public void reviewCellNo(String storeId, String checker) {
        SCell s=new SCell();
        s.setChecker(checker);
        s.setStoreId(storeId);
        this.sCellMapper.reviewCellNo(s);
        this.sCellMapper.updateDileCellTagNo(storeId);
    }

}
